home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / makstr.c < prev    next >
C/C++ Source or Header  |  1985-12-29  |  1KB  |  41 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ makstr - make a string of <length> characters.     */
  4. /*@        Copies from start to end and zero           */
  5. /*@        terminates.  Max of length.                 */
  6. /*@                                                    */
  7. /*@   Usage:     makstr(buf, st, end, len);            */
  8. /*@       where buf is the output buffer.              */
  9. /*@             st is a pointer to the start.          */
  10. /*@             end is a pointer to the end.           */
  11. /*@             len is the max length of buf.          */
  12. /*@                                                    */
  13. /*@    Returns a pointer to buf.                       */
  14. /*@                                                    */
  15. /*@*****************************************************/
  16.  
  17. #define EOS '\0'
  18.  
  19. /*******************************************************/
  20.  
  21. char *makstr(buffer, start, end, length)
  22. char *buffer, *start, *end;
  23. int length;
  24. {
  25.     char *sp;
  26.     int i, j, len;
  27.  
  28.     sp = start;
  29.     if ((len = end - start) > length - 1)
  30.         len = length - 1;
  31.  
  32.     for (j=i=0; i <= length; j=i++)
  33.         if (j < len)
  34.             buffer[j] = *sp++;
  35.         else {
  36.             buffer[j] = EOS;
  37.             break;
  38.         }
  39.     return buffer;
  40. }
  41.